@namespace MudBlazor
@using MudBlazor.Interfaces
@inherits MudComponentBase


<div @attributes="UserAttributes" Class="@Classname" Style="@Style" 
        @onmouseenter="@MouseEnter"
        @onmouseleave="@MouseLeave"
        @oncontextmenu:preventDefault="@(ActivationEvent == MouseEvent.RightClick ? true : false)">
    @if (ActivatorContent != null)
    {
        <CascadingValue Value="@((IActivatable) this)" IsFixed="true">
            <div @onclick="ToggleMenu" @ontouchend="@(ActivationEvent == MouseEvent.RightClick ? ToggleMenuTouch : null)" @oncontextmenu="@(ActivationEvent==MouseEvent.RightClick ? ToggleMenu : null)" disabled="@Disabled" class="@ActivatorClassname">
                @ActivatorContent
            </div>
        </CascadingValue>
    }
    else if (String.IsNullOrEmpty(Icon))
    {
        <MudButton StartIcon="@StartIcon"
                EndIcon="@EndIcon"
                IconColor="@IconColor"
                Color="@Color"
                Size="@Size"
                Variant="@Variant"
                Disabled="@Disabled"
                DisableRipple="@DisableRipple"
                DisableElevation="@DisableElevation"
                OnClick="@ToggleMenu"
                @ontouchend="@(ActivationEvent == MouseEvent.RightClick ? ToggleMenuTouch : null)"
                @oncontextmenu="@(ActivationEvent==MouseEvent.RightClick ? ToggleMenu : null)">
            @Label
        </MudButton>
    }
    else
    {
        <MudIconButton Variant="@Variant" Icon="@Icon" Color="@Color" Size="@Size" Disabled="@Disabled" DisableRipple="@DisableRipple" DisableElevation="@DisableElevation" @onclick="@ToggleMenu" @ontouchend="@(ActivationEvent == MouseEvent.RightClick ? ToggleMenuTouch : null)" @oncontextmenu="@(ActivationEvent==MouseEvent.RightClick ? ToggleMenu : null)" />
    }
    @* The portal has to include  the cascading values inside, because it's not able to teletransport the cascade *@
    <MudPopover Open="@_isOpen" Class="@PopoverClass" MaxHeight="@MaxHeight" AnchorOrigin="@AnchorOrigin" TransformOrigin="@TransformOrigin" RelativeWidth="@FullWidth" Style="@PopoverStyle" @ontouchend:stopPropagation>
        <CascadingValue Value="@this">
            <MudList Class="@ListClass" Clickable="true" Dense="@Dense"  
                @onmouseenter="@MouseEnter"
                @onmouseleave="@MouseLeave">
                @ChildContent
            </MudList>
        </CascadingValue>
    </MudPopover>
    <MudOverlay Visible="@(_isOpen && ActivationEvent!=MouseEvent.MouseOver)" OnClick="@ToggleMenu" LockScroll="LockScroll" />
</div>
